package com.csgc.camera.widget.mask

import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView

import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R


class MaskWuLiu:MaskBase {

    private var waiMain: TextView?= null
    private var peiSong: TextView?= null

    constructor(context: Context?, id:Int) : super(context,null){
        if(id == 0){
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_liu_1, this, true)
        }else if(id == 1){
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_liu_2, this, true)
        }
        dateStyle = "yyyy-MM-dd"
        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()



    }

    private fun initView(){

        date = findViewById(R.id.tv_wu_liu_date)
        time = findViewById(R.id.tv_wu_liu_time)
        week = findViewById(R.id.tv_wu_liu_week)
        location = findViewById(R.id.tv_wu_liu_location)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        location?.text = MaskConfig.maskLocation

        waiMain = findViewById(R.id.tv_wu_liu_wai_mai_people)
        peiSong = findViewById(R.id.tv_wu_liu_people)

        changeDateTime()
        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(Color.WHITE)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }
        val maskType = MaskPreference.instance.getMaskType()

        MaskConfig.maskMap[maskType]?.forEach {
            if (it.title == "配送员"){
                peiSong?.text = it.content
            }else if (it.title == "外卖员"){
                waiMain?.text = it.content
            }
        }


    }



    override fun updateItemContent(title: String, content: String) {
        super.updateItemContent(title, content)
        if (title == "配送员"){
            peiSong?.text = content
        }else if (title == "外卖员"){
            waiMain?.text = content
        }

    }


}